package com.dirven.game.wall;

import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.dirven.game.DirVenGame;
import com.dirven.game.Grid;

public class WallGlow {
	
	private static WallGlowLS northLS, southLS;
	private static WallGlowCenterTop northC, southC;
	private static WallGlowRS northRS, southRS;
	
	private static WallGlowTL westTL, eastTR;
	private static WallGlowCenterLeft westC, eastC;
	private static WallGlowBL westBL, eastBR;
	
	public static void renderNorth(SpriteBatch batch) {
		if(northLS == null) {
			northLS = new WallGlowLS(0, DirVenGame.screenHeight-8);
		}
		if(northC == null) {
			northC = new WallGlowCenterTop((float)northLS.getWidth(), (float)DirVenGame.screenHeight-8, (int)(DirVenGame.screenWidth-northLS.getWidth()*2));
		}
		if(northRS == null) {
			northRS = new WallGlowRS(DirVenGame.screenWidth, DirVenGame.screenHeight-8);
		}
		
		// Draw walls
		northLS.draw(batch);
		northC.draw(batch);
		northRS.draw(batch);
	}
	
	public static void renderSouth(SpriteBatch batch) {
		if(southLS == null) {
			southLS = new WallGlowLS(0, 0);
			southLS.flip(false, true);
		}
		if(southC == null) {
			southC = new WallGlowCenterTop((float)southLS.getWidth(), 0, (int)(DirVenGame.screenWidth-southLS.getWidth()*2));
			southC.flip(false, true);
		}
		if(southRS == null) {
			southRS = new WallGlowRS(DirVenGame.screenWidth, 0);
			southRS.flip(false, true);
		}
		
		// Draw walls
		southLS.draw(batch);
		southC.draw(batch);
		southRS.draw(batch);
	}
	
	public static void renderEast(SpriteBatch batch) {
		if(eastTR == null) {
			eastTR = new WallGlowTL(DirVenGame.screenWidth-8, DirVenGame.screenHeight-32);
			eastTR.flip(true, false);
		}
		if(eastC == null) {
			eastC = new WallGlowCenterLeft(DirVenGame.screenWidth-8, eastTR.getHeight(), (int)(DirVenGame.screenHeight-eastTR.getHeight()*2));
			eastC.flip(true, false);
		}
		if(eastBR == null) {
			eastBR = new WallGlowBL(DirVenGame.screenWidth-8, 0);
			eastBR.flip(true, false);
		}
		
		// Draw walls
		eastTR.draw(batch);
		eastC.draw(batch);
		eastBR.draw(batch);
	}
	
	public static void renderWest(SpriteBatch batch) {
		if(westTL == null) {
			westTL = new WallGlowTL(0, DirVenGame.screenHeight-32);
		}
		if(westC == null) {
			westC = new WallGlowCenterLeft(0, westTL.getHeight(), (int)(DirVenGame.screenHeight-westTL.getHeight()*2));
		}
		if(westBL == null) {
			westBL = new WallGlowBL(0, 0);
		}
		
		// Draw walls
		westTL.draw(batch);
		westC.draw(batch);
		westBL.draw(batch);
	}
	
	public static void render(SpriteBatch batch) {
		if( Grid.wallNorthBlocked == false ) {
			renderNorth(batch);
		}
		if( Grid.wallSouthBlocked == false ) {
			renderSouth(batch);
		}
		if( Grid.wallEastBlocked == false ) {
			renderEast(batch);
		}
		if( Grid.wallWestBlocked == false ) {
			renderWest(batch);
		}
	}

	public static void dispose() {
		northLS = null;
		southLS = null;
		northC = null;
		southC = null;
		northRS = null;
		southRS = null;
		westTL = null;
		eastTR = null;
		westC = null;
		eastC = null;
		westBL = null;
		eastBR = null;	
		
	}
}
